<template>
  <Page class="bg-[#f5f7fa] min-h-screen">
    <!-- 顶部蓝色渐变背景 -->
    <view class="fixed top-0 left-0 w-full z-[3] h-[250rpx] bg-gradient-to-b from-[#2196F3] to-[#6ec6ff] rounded-b-[40rpx]"></view>

    <!-- 吸顶标题与导航栏 -->
    <view class="sticky top-0 z-30 w-[750rpx] box-border pt-[32rpx] pb-[0] bg-transparent">
      <PageHeader title="" :showBack="true" :onlyBack="true" />
      <view class="text-[36rpx] w-full z-1 events-none text-center font-bold text-white mb-[24rpx] flex justify-center items-center relative">
        <text>我的发布</text>
      </view>

      <!-- 导航选项：日结、悬赏、招聘 -->
      <view class="flex overflow-x-auto gap-x-[18rpx] py-[10rpx] px-[32rpx] scrollbar-hide">
        <view
          v-for="(nav, index) in navOptions"
          :key="index"
          class="px-[32rpx] py-[12rpx] rounded-[24rpx] text-[26rpx] font-medium cursor-pointer transition-all duration-200 border border-transparent whitespace-nowrap flex-shrink-0"
          :class="activeNav === nav ? 'bg-gradient-to-r from-[#2196F3] to-[#6ec6ff] text-white font-bold shadow-md border-[#2196F3]' : 'bg-white/80 text-[#2196F3]/80 hover:bg-white'"
          @click="activeNav = nav"
        >
          {{ nav.name }}
        </view>
      </view>
    </view>

    <!-- 内容区 -->
    <view class="pt-[20rpx] pb-[32rpx] px-[0] mt-[30rpx]">
      <view class="p-[24rpx_32rpx] flex flex-col gap-y-[28rpx]">
        <!-- 空状态 -->
        <EmptyState v-if="currentItems.length === 0" :type="activeNav" />

        <!-- 项目展示组件 -->
        <ProjectShowItem
          v-for="(item, index) in currentItems"
          :key="item.id"
          :item="item"
          @click="handleItemClick(item)"
          @viewDetails="handleViewDetails(item)"
          @delete="handleDelete(item)"
          @refresh="refreshCurrentList"
          v-if="activeNav.key === '5'"
        />

        <!-- 日结招聘组件 -->
        <DailyRecruitmentItem
          v-for="(item, index) in currentItems"
          :key="item.id"
          :item="item"
          @click="handleItemClick(item)"
          @viewDetails="handleViewDetails(item)"
          @delete="handleDelete(item)"
          @refresh="refreshCurrentList"
          v-if="activeNav.key === '0'"
        />

        <!-- 悬赏任务组件 -->
        <RewardTaskItem
          v-for="(item, index) in currentItems"
          :key="item.id"
          :item="item"
          @click="handleItemClick(item)"
          @viewDetails="handleViewDetails(item)"
          @apply="handleTaskApply(item)"
          @delete="handleDelete(item)"
          @refresh="refreshCurrentList"
          v-if="activeNav.key === '1'"
        />

        <!-- 工厂招聘组件 -->
        <FactoryRecruitmentItem
          v-for="(item, index) in currentItems"
          :key="item.id"
          :item="item"
          :recruitmentType="0"
          @edit="handleItemClick(item)"
          @viewDetails="handleViewDetails(item)"
          @contact="handleContactHR(item)"
          @delete="handleDelete(item)"
          v-if="activeNav.key === '2'"
        />

        <!-- 签到任务组件 -->
        <CheckInTaskItem
          v-for="(item, index) in currentItems"
          :key="item.id"
          :item="item"
          @refresh="refreshCurrentList"
          @viewDetails="handleViewDetails(item)"
          @detail="handleCheckIn(item)"
          @delete="handleDelete(item)"
          v-if="activeNav.key === '4'"
        />

        <!-- 特殊招聘组件 -->
        <FactoryRecruitmentItem
          v-for="(item, index) in currentItems"
          :key="item.id"
          :item="item"
          :recruitmentType="1"
          @edit="handleItemClick(item)"
          @viewDetails="handleViewDetails(item)"
          @contact="handleContactHR(item)"
          @delete="handleDelete(item)"
          v-if="activeNav.key === '3'"
        />
      </view>

      <!-- 加载更多 -->
      <view v-if="currentItems.length > 0" class="flex justify-center mt-[20rpx] mb-[30rpx]">
        <nut-button
          size="small"
          type="default"
          class="border-[#2196F3] text-[#2196F3] bg-transparent rounded-[20rpx] px-[36rpx] py-[10rpx] text-[24rpx] font-medium hover:bg-[#e3f2fd] transition-all duration-200 flex items-center justify-center"
          @click="handleLoadMore()"
        >
          <!-- <IconFont name="load-more" size="20" class="mr-[10rpx]" /> -->
          <span>加载更多</span>
        </nut-button>
      </view>
    </view>
  </Page>
</template>

<script setup>
import { ref, computed, onMounted, watch } from "vue";
import Taro from "@tarojs/taro";
import { IconFont } from "@nutui/icons-vue-taro";
// import { Button as nutButton } from "@nutui/nutui-taro";
// 引入封装的组件
import PublishedItem from "./components/PublishedItem.vue";
import EmptyState from "./components/EmptyState.vue";
import DailyRecruitmentItem from "./components/DailyRecruitmentItem.vue";
import FactoryRecruitmentItem from "./components/FactoryRecruitmentItem.vue";
import RewardTaskItem from "./components/RewardTaskItem.vue";
import CheckInTaskItem from "./components/CheckInTaskItem.vue";
import ProjectShowItem from "./components/ProjectShowItem.vue";
import { post } from "@/utils/request";
//import {number} from "unocss-preset-weapp/dist/utils";

// 导航选项（整合所有数据）
const navOptions = ref([
  { 
    name: "项目展示", 
    key: "5", 
    hasMore: true, 
    pageNo: 1, 
    pageSize: 10, 
    newItems: ref([]), 
    publishedItems: ref([]),
    apiUrl: "/groupTypes/myRelease",
    fetchFunction: () => fetchProjectShowData(),
    publishUrl: "/pages/project-show/edit",
    editUrl: (id) => `/pages/project-show/edit?id=${id}`,
    deleteUrl: "/groupTypes/updateStatus"
  },
  { 
    name: "日结招聘", 
    key: "0", 
    hasMore: true, 
    pageNo: 1, 
    pageSize: 10, 
    newItems: ref([]), 
    publishedItems: ref([]),
    apiUrl: "/recruitmentDaily/myRelease",
    fetchFunction: () => fetchRecruitmentDailyData(),
    publishUrl: "/pages/web/post-job-openings",
    editUrl: (id) => `/pages/publish/editTheDay?id=${id}&type=0`,
    deleteUrl: "/recruitmentDaily/updateMain"
  },
  { 
    name: "悬赏任务", 
    key: "1", 
    hasMore: true, 
    pageNo: 1, 
    pageSize: 10, 
    newItems: ref([]), 
    publishedItems: ref([]),
    apiUrl: "/task/myRelease",
    fetchFunction: () => fetchTaskData(),
    publishUrl: "/pages/webs/bounty",
    editUrl: (id) => `/pages/edit/bounty?taskId=${id}&type=1`,
    deleteUrl: "/task/updateMainStatus"
  },
  { 
    name: "工厂招聘", 
    key: "2", 
    hasMore: true, 
    pageNo: 1, 
    pageSize: 10, 
    newItems: ref([]), 
    publishedItems: ref([]),
    apiUrl: "/recruitment/myRelease",
    fetchFunction: () => fetchRecruitmentData(0),
    publishUrl: "/pages/web/post-job-openings",
    editUrl: (id) => `/pages/publish/factoryRecruitmentEditor?id=${id}&type=2`,
    deleteUrl: "/recruitment/updateMain"
  },
  { 
    name: "签到任务", 
    key: "4", 
    hasMore: true, 
    pageNo: 1, 
    pageSize: 10, 
    newItems: ref([]), 
    publishedItems: ref([]),
    apiUrl: "/check/myRelease",
    fetchFunction: () => fetchCheckInTheTaskData(),
    publishUrl: "/pages/post/checkin",
    editUrl: (id) => `/pages/publish/checkinEditor?id=${id}&type=4`,
    deleteUrl: "/check/updateStatus"
  },
  // { 
  //   name: "特殊招聘", 
  //   key: "3", 
  //   hasMore: true, 
  //   pageNo: 1, 
  //   pageSize: 10, 
  //   newItems: ref([]), 
  //   publishedItems: ref([]),
  //   apiUrl: "/recruitment/myRelease",
  //   fetchFunction: () => fetchRecruitmentData(1),
  //   publishUrl: "/pages/web/post-job-openings",
  //   editUrl: (id) => `/pages/publish/speRecruitmentEditor?id=${id}&type=3`,
  //   deleteUrl: "/recruitment/updateMain"
  // }
]);

// 使用对象引用而不是索引
const activeNav = ref(navOptions.value[0]);


/**
 * 统一的数据刷新函数
 * @description 根据当前激活的导航类型刷新对应数据
 */
const refreshCurrentData = async () => {
  const currentNav = activeNav.value;
  console.log("currentType === 》", currentNav.key);
  
  // 重置分页状态
  currentNav.pageNo = 1;
  currentNav.hasMore = true;
  currentNav.publishedItems.value = [];
  
  // 调用对应的数据获取函数
  if (currentNav.fetchFunction) {
    await currentNav.fetchFunction();
  } else {
    console.warn('未找到对应的数据获取函数:', currentNav.key);
  }
};

/**
 * Taro 原生下拉刷新事件处理
 * @description 处理用户下拉刷新操作
 */
const onPullDownRefresh = async () => {
  try {
    console.log('开始下拉刷新...');
    await refreshCurrentData();
    
    // 显示刷新成功提示
    Taro.showToast({
      title: '刷新成功',
      icon: 'success',
      duration: 1500
    });
  } catch (error) {
    console.error('刷新数据失败:', error);
    Taro.showToast({
      title: '刷新失败，请重试',
      icon: 'error',
      duration: 2000
    });
  } finally {
    // 停止下拉刷新动画
    Taro.stopPullDownRefresh();
  }
};

// 启用 Taro 原生下拉刷新
Taro.usePullDownRefresh(onPullDownRefresh);


// 当前显示的内容
const currentItems = computed(() => {
  const currentNav = activeNav.value;
  const items = currentNav.publishedItems.value || [];
  
  // 悬赏任务需要特殊排序：未支付的排在前面
  if (currentNav.key === "1") {
    return items.sort((a, b) => {
      // 核心排序逻辑：未支付（0）排在已支付（1）前面
      if (a.pay_status === 0 && b.pay_status === 1) {
        return -1; // a在前
      } else if (a.pay_status === 1 && b.pay_status === 0) {
        return 1; // b在前
      } else {
        // 支付状态相同的情况下，不进行排序
        return 0;
      }
    });
  }
  
  return items;
});

const handleCheckIn = (item) => {
  console.log("handleCheckIn === 》", item);
  Taro.navigateTo({
    url: `/pages/edit/checkin?id=${item.id}&type=${activeNav.value}`,
  }).catch((err) => {
    console.error("跳转详情页失败：", err);
  });
};

watch(activeNav, (newNav) => {
  console.log("activeNav === 》", newNav.key);
  // 重置新导航的分页状态
  newNav.pageNo = 1;
  newNav.hasMore = true;
  newNav.publishedItems.value = [];
  
  // 调用对应的数据获取函数
  if (newNav.fetchFunction) {
    newNav.fetchFunction();
  }
});

const getListUrl = () => {
  const currentNav = activeNav.value;
  return currentNav.apiUrl;
};

// 处理发布新内容
const handleNewPublish = () => {
  const currentNav = activeNav.value;
  
  Taro.navigateTo({
    url: currentNav.publishUrl,
  }).catch((err) => {
    console.error("跳转发布页失败：", err);
  });
};

// 处理内容项点击
const handleItemClick = (item) => {
  const currentNav = activeNav.value;
  console.log("===>", item, currentNav.key);

  Taro.navigateTo({
    url: currentNav.editUrl(item.id),
  }).catch((err) => {
    console.error("跳转编辑页失败：", err);
  });
};

// 处理管理按钮点击
const handleViewDetails = (item) => {
  console.log("===>", item);
  const currentNav = activeNav.value;
  // 存入全局数据
  // if(currentNav.key === "1"){
  const maps = {
    "0": "daily",
    "1": "task",
    "2": "recruitment",
    "3": "recruitment",
    "4": "checkin",
    "5": "project", // 添加项目展示的映射
  };
  // alert(maps[currentNav.key])
  Taro.navigateTo({
    url: `/pages/post/applicants?taskId=${item.id}&type=${maps[currentNav.key]}`,
  });
  // }
  // else{
  //   Taro.navigateTo({
  //     url: `/pages/post/applicants?taskId=${item.id}&type=${activeNav.value}`,
  //   })
  // }
};

// 处理删除按钮点击
const handleDelete = (item) => {
  const currentNav = activeNav.value;
  const url = currentNav.deleteUrl;
  console.log("删除内容：", item);
  Taro.showModal({
    title: "确认终止",
    content: "确定要终止该发布吗？",
    success: (res) => {
      if (res.confirm) {
        post(url, {
          id: item.id,
          status: 5,
        }).then((res) => {
          console.log("删除结果：", res);
          if (res.code === 0) {
            Taro.showToast({
              title: "终止成功",
              icon: "success",
              duration: 2000,
            });
            // handleLoadMore(activeNav.value);
            refreshCurrentList();
          } else {
            Taro.showToast({
              title: "终止失败",
              icon: "none",
              duration: 2000,
            });
          }
        });
      }
    },
  });
};

const getTaskList = () => {
  const url = getListUrl();
  const currentNav = activeNav.value;
  const param = {
    pageNo: 1,
    pageSize: 100,
  };
  
  // 根据不同的导航类型添加特定参数
  if (currentNav.key === "1") {
    param.stage = 0;
  }
  if (currentNav.key === "2") {
    param.recruitmentType = 0;
  }
  if (currentNav.key === "3") {
    param.recruitmentType = 1;
  }
  post(url, param).then((res) => {
    console.log("获取任务列表：", res);
    taskList.value = res.data.map((item) => {
      return item.columns;
    });
  });
};

onMounted(() => {
  //getTaskList();
  fetchRecruitmentDailyData();
  // fetchTaskData();
  // fetchRecruitmentData(0);
  // fetchRecruitmentData(1);
  // fetchCheckInTheTaskData();
});

// 加载更多
let isLoading = false; // 是否正在加载

//获取我发布的日结数据
const fetchRecruitmentDailyData = () => {
  const dailyNav = navOptions.value.find(nav => nav.key === "0");
  if (!dailyNav) return;
  
  //没有更多时直接返回防止重复请求
  if (!dailyNav.hasMore) {
    Taro.showToast({ title: "没有更多了", icon: "none" });
    return;
  }
  Taro.showToast({
    title: "正在加载",
    icon: "loading",
    duration: 1000,
  });
  try {
    //请求接口
    post("/recruitmentDaily/myRelease", {
      pageNo: dailyNav.pageNo,
      pageSize: dailyNav.pageSize,
    }).then((res) => {
      console.log("日结===>", res);
      const newItems = res.data.map((item) => ({
        ...item.columns,
        member_id: item.columns.member_id,
        publishTime: item.columns.create_time,
        time_frame: item.columns.time_frame,
        pay_number: item.columns.pay_number,
        jobTitle: item.columns.position_name,
        desc: item.columns.description,
        type: item.columns.type,
        experience: item.columns.experience,
        dailySalary: item.columns.salary,
        hireCount: item.columns.number,
        pay_status: item.columns.pay_status,
        update_time: item.columns.update_time,
        name: item.columns.name,
        corporate_name: item.columns.corporate_name,
        workLocation: item.columns.location,
        id: item.columns.id,
        workDate: item.columns.deadline,
        status: item.columns.status,
        statusClass: item.columns.status,
        deadline: item.columns.deadline,
        description: item.columns.description,
      }));
      dailyNav.newItems.value = newItems;
      dailyNav.publishedItems.value = [...dailyNav.publishedItems.value, ...newItems];
      
      // 检查是否还有更多数据
      if (newItems.length < dailyNav.pageSize) {
        dailyNav.hasMore = false;
        Taro.showToast({ title: "没有更多了", icon: "none" });
      } else {
        dailyNav.pageNo++; // 没到底，页码+1，下次加载下一页
      }
    });
  } catch (err) {
    // 捕获错误并打印堆栈
    console.error("日结数据加载错误:", err); // 错误信息
    console.error("错误堆栈:", err.stack); // 错误堆栈（关键）
    Taro.showToast({ title: "加载失败!!", icon: "none" });
    //console.log("err",err)
  } finally {
    isLoading = false; // 结束加载
    //Taro.hideToast(); // 关闭加载提示
  }
};
//获取我发布的悬赏数据
const fetchTaskData = () => {
  const taskNav = navOptions.value.find(nav => nav.key === "1");
  if (!taskNav) return;
  
  console.log("fetchTaskData === 909090");
  if (!taskNav.hasMore) {
    Taro.showToast({ title: "没有更多了", icon: "none" });
    return;
  }
  Taro.showToast({
    title: "正在加载",
    icon: "loading",
    duration: 1000,
  });
  try {
    //请求接口
    post("/task/myRelease", {
      pageNo: taskNav.pageNo,
      pageSize: taskNav.pageSize,
      stage: 0,
    }).then((res) => {
      console.log("res === 》", res);
      const newItems = res.data.map((item) => ({
        ...item.columns,
        member_id: item.columns.member_id,
        publishTime: item.columns.create_time,
        time_frame: item.columns.time_frame,
        applyCount: item.columns.pay_number,
        taskTitle: item.columns.title,
        desc: item.columns.describe_str,
        type: item.columns.type,
        experience: item.columns.experience,
        totalReward: item.columns.total_amount,
        number: item.columns.number,
        pay_status: item.columns.pay_status,
        update_time: item.columns.update_time,
        name: item.columns.name,
        corporate_name: item.columns.corporate_name,
        location: item.columns.location,
        id: item.columns.id,
        deadline: item.columns.deadline,
        statusClass: item.columns.status,
        status: item.columns.status,
      }));
      taskNav.newItems.value = newItems;
      taskNav.publishedItems.value = [...taskNav.publishedItems.value, ...newItems];
      console.log("newItems2", newItems);
      
      // 检查是否还有更多数据
      if (newItems.length < taskNav.pageSize) {
        taskNav.hasMore = false;
        Taro.showToast({ title: "没有更多了", icon: "none" });
      } else {
        taskNav.pageNo++; // 没到底，页码+1，下次加载下一页
      }
    });
  } catch (err) {
    // 捕获错误并打印堆栈
    console.error("日结数据加载错误:", err); // 错误信息
    console.error("错误堆栈:", err.stack); // 错误堆栈（关键）
    Taro.showToast({ title: "加载失败", icon: "none" });
  } finally {
    isLoading = false; // 结束加载
    //Taro.hideToast(); // 关闭加载提示
  }
};
//获取我发布的工厂招聘数据
const fetchRecruitmentData = (n) => {
  const key = n == 0 ? "2" : "3"; // 工厂招聘key="2", 特殊招聘key="3"
  const recruitmentNav = navOptions.value.find(nav => nav.key === key);
  if (!recruitmentNav) return;
  
  if (!recruitmentNav.hasMore) {
    Taro.showToast({ title: "没有更多了", icon: "none" });
    return;
  }
  Taro.showToast({
    title: "正在加载",
    icon: "loading",
    duration: 1000,
  });
  try {
    //请求接口
    post("/recruitment/myRelease", {
      pageNo: recruitmentNav.pageNo,
      pageSize: recruitmentNav.pageSize,
      recruitmentType: n,
    }).then((res) => {
      const newItems = res.data.map((item) => ({
        ...item.columns,
        member_id: item.columns.member_id,
        publishTime: item.columns.create_time,
        time_frame: item.columns.time_frame,
        pay_number: item.columns.pay_number,
        jobTitle: item.columns.position_name,
        desc: item.columns.description,
        type: item.columns.type,
        experience: item.columns.experience,
        salary_min: item.columns.salary_min,
        salary_max: item.columns.salary_max,
        number: item.columns.number,
        pay_status: item.columns.pay_status,
        updateTime: item.columns.update_time,
        name: item.columns.name,
        factoryName: item.columns.corporate_name,
        workCity: item.columns.location,
        id: item.columns.id,
        deadline: item.columns.deadline,
        statusClass: item.columns.status,
        status: item.columns.status,
        description: item.columns.description,
        special: item.columns.recruitment_type == 1,
      }));

      recruitmentNav.newItems.value = newItems;
      recruitmentNav.publishedItems.value = [...recruitmentNav.publishedItems.value, ...newItems];
      console.log("newItems", newItems);
    });
      // 检查是否还有更多数据
      if (newItems.length < recruitmentNav.pageSize) {
        recruitmentNav.hasMore = false;
        Taro.showToast({ title: "没有更多了", icon: "none" });
      } else {
        recruitmentNav.pageNo++; // 没到底，页码+1，下次加载下一页
      }
  } catch (err) {
    // 捕获错误并打印堆栈
    console.error("日结数据加载错误:", err); // 错误信息
    console.error("错误堆栈:", err.stack); // 错误堆栈（关键）
    Taro.showToast({ title: "加载失败", icon: "none" });
  } finally {
    isLoading = false; // 结束加载
    //Taro.hideToast(); // 关闭加载提示
  }
};

//获取我发布的签到任务
const fetchCheckInTheTaskData = () => {
  const checkInNav = navOptions.value.find(nav => nav.key === "4");
  if (!checkInNav) return;
  
  if (!checkInNav.hasMore) {
    Taro.showToast({ title: "没有更多了", icon: "none" });
    return;
  }
  Taro.showToast({
    title: "正在加载",
    icon: "loading",
    duration: 1000,
  });
  try {
    //请求接口
    post("/check/myRelease", {
      pageNo: checkInNav.pageNo,
      pageSize: checkInNav.pageSize,
    }).then((res) => {
      console.log("res === 》", res);
      const newItems = res.data.map((item) => ({
        ...item.columns,
        member_id: item.columns.member_id,
        publishTime: item.columns.create_time,
        time_frame: item.columns.time_frame,
        pay_number: item.columns.pay_number,
        title: item.columns.title,
        desc: item.columns.describe_str,
        full_address: item.columns.full_address,
        type: item.columns.type,
        experience: item.columns.experience,
        amount: item.columns.task_amount,
        number: item.columns.number,
        pay_status: item.columns.pay_status,
        update_time: item.columns.update_time,
        name: item.columns.name,
        corporate_name: item.columns.corporate_name,
        location: item.columns.location,
        id: item.columns.id,
        deadline: item.columns.deadline,
        statusClass: item.columns.status,
      }));
      checkInNav.newItems.value = newItems;
      checkInNav.publishedItems.value = [...checkInNav.publishedItems.value, ...newItems];
      console.log("newItems", newItems);
    });
      // 检查是否还有更多数据
      if (newItems.length < checkInNav.pageSize) {
        checkInNav.hasMore = false;
        Taro.showToast({ title: "没有更多了", icon: "none" });
      } else {
        checkInNav.pageNo++; // 没到底，页码+1，下次加载下一页
      }
  } catch (err) {
    // 捕获错误并打印堆栈

    Taro.showToast({ title: "加载失败!!", icon: "none" });
  } finally {
    isLoading = false; // 结束加载
    //Taro.hideToast(); // 关闭加载提示
  }
};

// 加载更多数据
const handleLoadMore = () => {
  const currentNav = activeNav.value;
  if (currentNav.fetchFunction) {
    currentNav.fetchFunction();
  }
};

/**
 * 刷新当前 activeNav 列表，从第一页开始
 * @param {object} navOption - 可选的导航对象，默认使用当前 activeNav
 */
const refreshCurrentList = (navOption = null) => {
  console.log("refreshCurrentList", navOption);
  const currentNav = navOption || activeNav.value;

  // 显示刷新提示
  Taro.showToast({
    title: "正在刷新...",
    icon: "loading",
    duration: 1000,
  });

  // 重置分页参数
  currentNav.pageNo = 1;
  currentNav.hasMore = true;
  currentNav.publishedItems.value = [];

  // 重新加载数据
  if (currentNav.fetchFunction) {
    currentNav.fetchFunction();
  }

  console.log(`刷新列表 - 导航类型: ${currentNav.key}`);
};

/**
 * 获取项目展示数据
 * @description 获取用户发布的项目展示列表
 */
const fetchProjectShowData = async () => {
  if (isLoading) {
    return;
  }
  
  isLoading = true;
  
  try {
    Taro.showToast({
      title: "正在加载",
      icon: "loading",
      duration: 1000,
    });
    
    // 调用项目展示我的发布接口
    const projectNav = navOptions.value.find(nav => nav.key === "5");
    if (!projectNav) return;
    
    const res = await post("/groupTypes/myRelease", {
      pageNo: projectNav.pageNo,
      pageSize: projectNav.pageSize,
    });
    
    console.log("项目展示数据 === 》", res);
    
    if (res.code === 0 && res.data) {
      const newItems = res.data.map((item) => ({
        ...item.columns,
        id: item.columns.id,
        title: item.columns.title,
        content: item.columns.content,
        pics: item.columns.pics,
        status: item.columns.status,
        rangeType: item.columns.rangeType,
        create_time: item.columns.create_time,
        update_time: item.columns.update_time,
        publishTime: item.columns.create_time,
        statusClass: item.columns.status,
      }));
      
      projectNav.publishedItems.value = [...projectNav.publishedItems.value, ...newItems];
      
      // 检查是否还有更多数据
      if (newItems.length < projectNav.pageSize) {
        projectNav.hasMore = false;
        Taro.showToast({ title: "没有更多了", icon: "none" });
      } else {
        projectNav.pageNo++; // 没到底，页码+1，下次加载下一页
      }
    }
  } catch (error) {
    console.error("获取项目展示数据失败:", error);
    Taro.showToast({ 
      title: "加载失败", 
      icon: "none",
      duration: 2000
    });
  } finally {
    isLoading = false;
  }
};
</script>
